<template>
  <div class="mod-menu">
    <el-form :inline="true">
      <el-form-item>
        <el-button type="primary" @click="addOrUpdateHandle()">新增</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="dataList" row-key="Id" border style="width: 100%; ">
      <el-table-column prop="icon" align="center" label="银行卡图标">
        <template slot-scope="scope">
          　　　　<el-popover placement="top-start" trigger="hover">
            <a :href="scope.row.icon" target="_blank" title="查看最大化图片"><img :src="scope.row.icon" style="width: 300px;height: 300px" /></a>
            <img slot="reference" :src="scope.row.icon" @click="$openImg(scope.row.icon)" style="width: 50px;height: 50px; cursor:pointer" />
          </el-popover>
          　　</template>
      </el-table-column>
      <el-table-column prop="name" align="center" label="银行卡名称">
      </el-table-column>
      <el-table-column prop="acronym" align="center" label="银行卡缩写">
      </el-table-column>
      <el-table-column prop="sort" align="center" label="排序号">
      </el-table-column>
      <el-table-column fixed="right" header-align="center" align="center" label="操作">
        <template slot-scope="scope">
          <!-- <el-button type="text" size="small" class="c-update" @click="addOrUpdateHandle(scope.row.id)">编辑</el-button> -->
          <el-button type="text" size="small" class="c-error" @click="businessDelgoods(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" :current-page="params.page" :page-sizes="[10, 20, 50, 100]" :page-size="params.limit" :total="totalPage" layout="total, sizes, prev, pager, next, jumper"></el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <bank-card-add-update v-if="addOrUpdateVisible" ref="bankCardAddUpdate" @updataList='updataList'></bank-card-add-update>
  </div>
</template>

<script>
import seviceApi from '@/api/serviceApi.js'
import bankCardAddUpdate from './bank-card-add-update.vue'
export default {
  data () {
    return {
      dataForm: {},
      dataList: [],
      params: {
        page: 1,
        limit: 10
      },
      totalPage: 0,
      dataListLoading: false,
      addOrUpdateVisible: false
    }
  },
  components: {
    bankCardAddUpdate
  },
  mounted () {
    this.getList()
  },
  methods: {
    // 更新列表
    updataList (e) {
      if (e == 1) {
        this.getList()
      }
    },
    getList () {
      seviceApi.getBankcardIconList(this.params).then(res => {
        if (res && res.data.code == 200) {
          this.dataList = res.data.page.list
          this.totalPage = res.data.page.totalCount
        }
      })
    },
    // 每页数
    sizeChangeHandle (val) {
      this.params.page = 1
      this.params.limit = val
      this.getList()
    },
    // 当前页
    currentChangeHandle (val) {
      this.params.page = val
      this.getList()
    },
    /**
     * 删除
     * */
    businessDelgoods (row) {
      this.$confirm(`是否删除 [ ${row.name} ] ?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        seviceApi.delBankCardIcon(row.id).then(res => {
          if (res.data && res.data.code == 200) {
            this.$message.success('删除成功！')
            if (this.dataList.length == 1) {
              this.params.page = 1
            }
            this.getList()
          }
        })
      }).catch(() => { })
    },
    // 新增 / 修改
    addOrUpdateHandle (id) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.bankCardAddUpdate.init(id)
      })
    }
  }
}
</script>
